<template>
	<view class="settle page bgf6 ">
		<view class="bgff0 pl10 tip" v-if="show">{{msg}}</view>
		<!-- 非法人对私结算 -->
		<view class="bgf6 pb50 px15">

			<view class="bgff r3 mt12">
				<view class="px12 pt12">
					<text class="cff0">*</text>
					<text class="pl4">法人证件：</text>
				</view>
				<view class="flex flexC flexJC">
					<view class="p12 aliC">
						<view @click="upload('idcard1')" class="flex flexC flexCol flexJC box134">
							<image v-if="idcard1 == '' || idcard1 == null" class="w134 bg" src="../static/updatebg.png"
								mode="aspectFill"></image>
							<image v-else class="w134 bg" :src="idcard1" mode="aspectFill"></image>

							<image class="w36" src="../static/camera.png"></image>
						</view>
						<view class="mt12">
							<text class="cff0">*</text>
							<text class="pl4 fs12">法人身份证人像面</text>
						</view>
					</view>
					<view class="p12 aliC">
						<view @click="upload('idcard2')" class="flex flexC flexCol flexJC box134">
							<image v-if="idcard2 == ''  || idcard2 == null" class="w134 bg" src="../static/updatebg.png"
								mode="aspectFill"></image>
							<image v-else class="w134 bg" :src="idcard2" mode="aspectFill"></image>

							<image class="w36" src="../static/camera.png"></image>
						</view>
						<view class="mt12">
							<text class="cff0">*</text>
							<text class="fs12">法人身份证国徽面</text>
						</view>
					</view>
				</view>
			</view>



			<view class="bgff r3 mt12">
				<view class="px12 pt12">
					<text class="cff0">*</text>
					<text class="pl4">合同照片：</text>
				</view>
				<view class="flex flexC flexJC">
					<view class="p12 aliC">
						<view @click="upload('ht1')" class="flex flexC flexCol flexJC box134">
							<image v-if="ht1 == '' || ht1 == null" class="w134 bg" src="../static/updatebg.png"
								mode="aspectFill"></image>
							<image v-else class="w134 bg" :src="ht1" mode="aspectFill"></image>

							<image class="w36" src="../static/camera.png"></image>
						</view>
						<view class="mt12">
							<text class="cff0">*</text>
							<text class="pl4 fs12">合同第一页</text>
						</view>
					</view>
					<view class="p12 aliC">
						<view @click="upload('ht2')" class="flex flexC flexCol flexJC box134">
							<image v-if="ht2 == ''  || ht2 == null" class="w134 bg" src="../static/updatebg.png"
								mode="aspectFill"></image>
							<image v-else class="w134 bg" :src="ht2" mode="aspectFill"></image>

							<image class="w36" src="../static/camera.png"></image>
						</view>
						<view class="mt12">
							<text class="cff0">*</text>
							<text class="fs12">合同的最后一页</text>
						</view>
					</view>
				</view>
			</view>


			<view class="bgff r3 mt12">
				<view class="px12 pt12">
					<text class="cff0">*</text>
					<text class="pl4">其它资料：</text>
				</view>
				<view class="flex flexC flexJC">
					<view class="p12 aliC">
						<view @click="upload('yyzz')" class="flex flexC flexCol flexJC box134">
							<image v-if="yyzz == '' || yyzz == null" class="w134 bg" src="../static/updatebg.png"
								mode="aspectFill"></image>
							<image v-else class="w134 bg" :src="yyzz" mode="aspectFill"></image>

							<image class="w36" src="../static/camera.png"></image>
						</view>
						<view class="mt12">
							<text class="cff0">*</text>
							<text class="pl4 fs12">营业执照</text>
						</view>
					</view>
					<view class="p12 aliC">
						<view @click="upload('mt')" class="flex flexC flexCol flexJC box134">
							<image v-if="mt == ''  || mt == null" class="w134 bg" src="../static/updatebg.png"
								mode="aspectFill"></image>
							<image v-else class="w134 bg" :src="mt" mode="aspectFill"></image>

							<image class="w36" src="../static/camera.png"></image>
						</view>
						<view class="mt12">
							<text class="cff0">*</text>
							<text class="fs12">门头照片</text>
						</view>
					</view>
				</view>
			</view>


			<view class="bgff r3 mt12">
				<view class="px12 pt12">
					<text class="cff0">*</text>
					<text class="pl4">银行卡正面：</text>
				</view>
				<view class="flex flexC flexJC">
					<view class="p12 aliC">
						<view @click="upload('bank')" class="flex flexC flexCol flexJC box134">
							<image v-if="bank == '' || bank == null" class="w134 bg" src="../static/updatebg.png"
								mode="aspectFill"></image>
							<image v-else class="w134 bg" :src="bank" mode="aspectFill"></image>

							<image class="w36" src="../static/camera.png"></image>
						</view>
						<view class="mt12">
							<text class="cff0">*</text>
							<text class="pl4 fs12">结算人银行卡正面</text>
						</view>
					</view>
					<view class="p12 aliC">
						<view @click="upload('auth')" class="flex flexC flexCol flexJC box134">
							<image v-if="auth == ''  || auth == null" class="w134 bg" src="../static/updatebg.png"
								mode="aspectFill"></image>
							<image v-else class="w134 bg" :src="auth" mode="aspectFill"></image>

							<image class="w36" src="../static/camera.png"></image>
						</view>
						<view class="mt12">
							<text class="cff0"></text>
							<text class="fs12 cff0">非法人银行授权书(结算人为非法人必须上传)</text>
						</view>
					</view>
				</view>
			</view>


		</view>
		<!-- 下一步 -->
		<view class="bgf6c btn cff aliC py12" @click="next">提交</view>
	</view>
</template>

<script>
	import {
		ossUpload
	} from '@/js_sdk/jason-alioss-upload/oss.js'
	export default {
		data() {
			return {

				idcard1: '',
				idcard1Path: '',
				idcard2: '',
				idcard2Path: '',
				ht1: '',
				ht1Path: '',
				ht2: '',
				ht2Path: '',
				yyzz: '',
				yyzzPath: '',
				mt: '',
				mtPath: '',
				bank: '',
				bankPath: '',
				auth: '',
				authPath: '',
				shopId: '',
				show:false,
				msg:''

			};
		},

		onLoad(option) {
			this.shopId = option.shopId;
		},
		onShow() {
			this.info();
		},
		methods: {




			upload(type) {

				let that = this;

				uni.chooseImage({
					count: 1, //默认9
					fail(res) {
						console.info(res);
					},
					success: async (file) => {

						uni.showLoading({
							title: '上传中'
						})

						const {
							success,
							data
						} = await ossUpload(file.tempFilePaths[0], file.tempFiles[0].path, 'img/')
						uni.hideLoading();
						if (success) {
							console.info(data);
							console.info("===type===" + type);
							if (type == 'idcard1') {
								that.idcard1 = data;
							} else if (type == 'idcard2') {
								that.idcard2 = data;

							} else if (type == 'ht1') {
								that.ht1 = data;

							} else if (type == 'ht2') {
								that.ht2 = data;

							} else if (type == 'yyzz') {
								that.yyzz = data;

							} else if (type == 'mt') {
								that.mt = data;

							} else if (type == 'bank') {
								that.bank = data;

							} else if (type == 'auth') {
								that.auth = data;

							}
						} else {
							uni.showToast({
								icon: 'none',
								title: data
							})
						}
					}
				});


			},


			next() {


				if (this.idcard1 == '' || this.idcard2 == null) {
					uni.showToast({
						title: "请上传身份证正面",
						icon: 'none'
					});
					return;
				}

				if (this.ht1 == '' || this.ht2 == null) {
					uni.showToast({
						title: "请上传合同资料",
						icon: 'none'
					});
					return;
				}
				if (this.yyzz == '') {
					uni.showToast({
						title: "请上传营业执照",
						icon: 'none'
					});
					return;
				}
				if (this.mt == '') {
					uni.showToast({
						title: "请上传门头",
						icon: 'none'
					});
					return;
				}
				if (this.bank == '') {
					uni.showToast({
						title: "请上传结算银行卡",
						icon: 'none'
					});
					return;
				}



				let param = {
					shop_id: this.shopId,
					idcard1: this.idcard1,
					idcard2: this.idcard2,
					ht1: this.ht1,
					ht2: this.ht2,
					yyzz: this.yyzz,
					mt: this.mt,
					bank: this.bank,
					auth: this.auth
				}

				this.$api.addFile(param).then(res => {

					if (res.code == 1) {

						uni.showModal({
							title: "提示",
							content: "您提交的资料在1个工作日内审核，请耐心等待",
							showCancel: false,
							complete(res) {
								uni.navigateBack({
									delta: 1
								});
							}
						})

					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						});
					}
				})


			},

			radioChange(ev) {

			},
			radioChange2(ev) {

			},
			bankChange(ev) {

			},

			info() {

				let that = this;
				let param = {
					shop_id: this.shopId
				};

				this.$api.fileInfo(param).then(res => {
					
					if(res.data != null){
						
						if(res.data.status == 'refuse'){
							that.msg = res.data.msg;
							that.show = true;
							that.idcard1 = res.data.image.idcard1;
							that.idcard2 = res.data.image.idcard2;
							that.ht1 = res.data.image.ht1;
							that.ht2 = res.data.image.ht2;
							that.yyzz = res.data.image.yyzz;
							that.auth = res.data.image.auth;
							that.mt = res.data.image.mt;
							that.bank = res.data.image.bank;
							
						}
					}

				})

			},

			getDetail() {

				let that = this;
				let param = {
					id: this.shop_id
				};

				this.$api.merchantDetail(param).then(res => {

					if (res.code == 1) {


						that.frontPath = res.data.legalPersonIdCardFrontPath;
						that.frontUrl = res.data.legalPersonIdCardFront;
						that.frontSxf = res.data.legalPersonIdCardFrontSxf;

						that.backPath = res.data.legalPersonIdCardReversePath;
						that.backUrl = res.data.legalPersonIdCardReverse;
						that.backSxf = res.data.legalPersonIdCardReverseSxf;
						that.name = res.data.legalPersonName;
						that.idcard = res.data.legalPersonIdCardNo;
						that.startDate = res.data.fa_start;
						that.endDate = res.data.fa_end;
						if (that.endDate == -1) {
							that.isLong = true;
						}
						uni.setStorageSync("twoStep", res.data.two);

					} else {

					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.settle {
		.tip {
			line-height: 45rpx;
		}

		.pb50 {
			padding-bottom: 114rpx;
		}

		.box134 {
			width: 268rpx;
			height: 180rpx;
			position: relative;
		}

		.w134 {
			width: 268rpx;
			height: 180rpx;
			position: absolute;
			top: 0;
			left: 0;
		}

		.w36 {
			width: 72rpx;
			height: 72rpx;
			position: relative;
			z-index: 3;
		}

		.btn {
			position: fixed;
			bottom: 0;
			left: 0;
			width: 100vw;
			z-index: 10;
		}
	}
</style>